<div class="meetings index">
<?php if(isset($permission['Meeting']['Create']) && $permission['Meeting']['Create'] ): ?>
<p class='contentmenu'>[ <?php echo $html->link(__("Add new Meeting",true),array('committee'=>$dcommittee['Committee']['short_name'],'action'=>'add')); ?> ]
</p>
<?php endif; ?>
<h2><?php __('Meetings');?></h2>

<table cellpadding="0" cellspacing="0">
<tr>
    <th><?php __('No')?></th>
    <th><?php echo $paginator->sort('meeting_title',null,array('url'=>array('committee'=>$dcommittee['Committee']['short_name'])));?></th>
    <th><?php echo $paginator->sort('meeting_num',null,array('url'=>array('committee'=>$dcommittee['Committee']['short_name'])));?></th>
    <th><?php echo $paginator->sort('meeting_date',null,array('url'=>array('committee'=>$dcommittee['Committee']['short_name'])));?></th>
    <th><?php echo $paginator->sort('venue',null,array('url'=>array('committee'=>$dcommittee['Committee']['short_name'])));?></th>
    <th><?php echo __('Invitation',true);?></th>
    <?php 
    if ((isset($meetings[0]['auth']['secretariat']) && $meetings[0]['auth']['secretariat']) || (isset($meetings[0]['auth']['minute']) && $meetings[0]['auth']['minute'])) {
        echo '<th>'.__('Minutes',true).'</th>';
    }
    if ((isset($meetings[0]['auth']['secretariat']) &&$meetings[0]['auth']['secretariat'])|| (isset($permission['Report']['View']) && $permission['Report']['View'])) {
        echo '<th>'.__('Report',true).'</th>';
    }
    if ((isset($meetings[0]['auth']['secretariat']) && $meetings[0]['auth']['secretariat'])|| (isset($permission['Meetingtodo']['sum']) && $permission['Meetingtodo']['sum'])) {
        echo '<th>'.__('Todo',true).'</th>';
    }
     if ((isset($meetings[0]['auth']['secretariat']) && $meetings[0]['auth']['secretariat']) ||(isset($meetings[0]['auth']['attendance']) && $meetings[0]['auth']['attendance'])) {
        echo '<th>'.__('Attendance',true).'</th>';
    }
    if ($auth_user['User']['superuser'] || (isset($meetings[0]['auth']['secretariat']) && $meetings[0]['auth']['secretariat']) || (isset($meetings[0]['auth']['edit']) && $meetings[0]['auth']['edit'] )||(isset($meetings[0]['auth']['delete']) && $meetings[0]['auth']['delete'])) { ?>
    <th class="actions" colspan='2'><?php __('Actions');?></th>
    <?php } ?>
</tr>

<?php if (!count($meetings)) : ?>
<tr>
    <td colspan="10"><?php echo __('No record found',true); ?></td>
</tr>
<?php endif; ?>

<?php
$i = 0;
foreach ($meetings as $meeting):
    $class = null;
    if ($i++ % 2 == 0) {
        $class = ' class="altrow"';
    }
?>
<tr<?php echo $class;?>>
    <td><?php echo $i.'.';?></td>
    <td><?php echo $meeting['Meeting']['meeting_title']?></td>
    <td>
    <?php 
    if($auth_user['User']['superuser']||isset($meeting['auth']['Secretariat']) || (isset($meeting['auth']['View']) && $meeting['auth']['View'])){
        echo $html->link($meeting['Meeting']['meeting_num'],array('committee'=>$dcommittee['Committee']['short_name'],'action'=>'view','id'=>$meeting['Meeting']['id']),null,null,false);
    } else {
        echo $meeting['Meeting']['meeting_num'];
    }
    ?>
    </td>
    <td>
    <?php echo date(Configure::read('date_format'),strtotime($meeting['Meeting']['meeting_date'])); ?>&nbsp;
    <?php echo date(Configure::read('time_format'),strtotime($meeting['Meeting']['meeting_date'])); ?>
    </td>
    <td><?php echo $meeting['Meeting']['venue']; ?></td>
    <td class="actions">
    <?
    $displayed = 0;
    foreach ($meeting['Notification'] as $notification) {
        if ($notification['notification_sent'] && $notification['type'] == 'invite') {
            $displayed = 1;
            break;
        }
    }
    echo $displayed ? __('Invited',true): '-' ?>
    </td>
    <?php 
    if(isset($meeting['auth']['Secretariat']) ||(isset($meeting['auth']['Minute']) && $meeting['auth']['Minute'])){
        echo '<td class="actions">'.$html->link(__('Minutes', true), array('committee'=>$committee,'controller'=>'decisions','action'=>'printminutes',$meeting['Meeting']['id']), array('target'=>'_blank')).'</td>'; 
    }elseif($meeting['auth']['secretariat'] || $meeting['auth']['minute']){
        echo '<td class="actions">-</td>';
    }
    if(isset($meeting['auth']['Secretariat']) ||(isset($permission['Report']['View']) && $permission['Report']['View'])){
        echo '<td class="actions">'.$html->link(__('View', true), array('committee'=>$committee,'controller'=>'reports','action'=>'meeting',$meeting['Meeting']['id']), array('target'=>'_blank')).'</td>'; 
    }elseif($meeting['auth']['secretariat']){
        echo '<td class="actions">-</td>';
    }
    if (isset($meeting['auth']['Secretariat']) ||(isset($permission['Meetingtodo']['View']) && $permission['Meetingtodo']['View'])){
        echo '<td class="actions">'.$html->link(__('Todo', true), array('committee'=>$committee,'controller'=>'meetingtodos','action'=>'index', $meeting['Meeting']['id'])).'</td>';
    }elseif($meeting['auth']['secretariat']){
        echo '<td class="actions"> - </td>';
    }
    if (isset($meeting['auth']['Secretariat']) ||(isset($meeting['auth']['Attendance']) && $meeting['auth']['Attendance'])) {
        echo '<td class="actions">'.$html->link(__('Attendance', true), array('committee'=>$committee,'action'=>'attendance', $meeting['Meeting']['id'])).'</td>';
    }elseif($meeting['auth']['secretariat'] || !empty($meeting['auth']['attendance'])){
        echo '<td class="actions"> - </td>';
    }
    echo $this->element('crud',array('crudid'=>$meeting['Meeting']['id'],'permission'=>isset($meeting['auth'])?$meeting['auth']:null));
    ?>
</tr>
<?php endforeach; ?>

</table>
</div>

<div class="paging">
<?php echo $paginator->prev('<< '.__('previous', true), array('url'=>array('committee'=>$dcommittee['Committee']['short_name'])), null, array('class'=>'disabled'));?>
|     <?php echo $paginator->numbers(array('url'=>array('committee'=>$dcommittee['Committee']['short_name'])));?>
<?php echo $paginator->next(__('next', true).' >>', array('url'=>array('committee'=>$dcommittee['Committee']['short_name'])), null, array('class'=>'disabled'));?>
</div>
